<template>
  <div class="page">
    <p class="delivery">送货单列表</p>

    <div class="header">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="送货状态">
          <el-select v-model="formInline.status" placeholder="请选择">
            <el-option label="未送货" value="0"></el-option>
            <el-option label="已送货" value="1"></el-option>
            <el-option label="已验收" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="送货日期">
          <el-date-picker
            v-model="formInline.deliveryDate"
            value-format="yyyy-MM-dd"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="querylist()">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="table">
      <el-table
        :data="deliveryLists"
        border
        style="width: 100%;text-align:center"
      >
        <el-table-column type="index" width="50" label="序号">
        </el-table-column>
        <el-table-column prop="deliveryId" label="送货单号"> </el-table-column>
        <el-table-column prop="supplierShortName" label="客户名称">
        </el-table-column>
        <el-table-column prop="deliveryTypeNum" label="品种数量">
        </el-table-column>
        <el-table-column prop="totalWeight" label="总重量"> </el-table-column>
        <el-table-column prop="totalPrice" label="总金额"> </el-table-column>
        <el-table-column prop="address" label="送货地址"> </el-table-column>
        <el-table-column prop="deliveryDate" label="送货日期">
        </el-table-column>
        <el-table-column prop="deliveryStatus" label="送货状态">
          <template slot-scope="scope">
            {{ scope.row.deliveryStatus | deliveryStatusFitlter }}
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="200px">
          <template slot-scope="scope">
            <el-button type="primary" @click="todetail(scope.row.deliveryId)"
              >明细</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 分页数据 -->
    <el-pagination
      @current-change="handleCurrentChange"
      background
      :current-page="pagenum"
      :page-size="pagesize"
      layout="prev,pager,next"
      :total="total - 0"
      style="margin-top:20px;text-align:center"
    ></el-pagination>
  </div>
</template>

<script>
import { getDeliveryList, deleteDelivery } from "@/api/partner.js";
import { getUserId } from "@/utils/auth";
export default {
  filters: {
    deliveryStatusFitlter(value) {
      if (value === 0) {
        return "未送货";
      } else if (value === 1) {
        return "已送货";
      } else {
        return "已验收";
      }
    }
  },
  data() {
    return {
      formInline: {
        deliveryDate: "",
        status: ""
      },
      deliveryLists: [],
      // 显示第几页
      pagenum: 1,
      total: "",
      // 每页显示的数据
      pagesize: 10,
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    // 当前第几页
    handleCurrentChange(val) {
      this.pagenum = val;
      this.init();
    },
    init() {
      var data = {
        supplierId:Number(getUserId()),
        deliveryDate: this.formInline.deliveryDate,
        status: this.formInline.status,
        pageNo: this.pagenum
      };
      getDeliveryList(data).then(res => {
        console.log(res);
        this.deliveryLists = res.rows;
        this.total = res.total;
        this.pagesize = res.pageSize
      });
    },
    // 搜索
    querylist() {
      this.init();
    },
    todetail(id) {
      this.$router.push({
        path: "deliverydetail",
        query: { deliveryId: id }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.page {
  padding: 20px 20px;
  .delivery {
    font-size: 22px;
    margin-bottom: 60px;
  }
  .header {
    margin-bottom: 70px;
  }
}
</style>
